package com.etc.service.impl;

import java.math.BigDecimal;
import java.util.List;
import com.etc.dao.GamesDao;
import com.etc.dao.impl.GamesDaoImpl;
import com.etc.entity.Games;
import com.etc.entity.PageInfo;
import com.etc.service.GamesService;

public class GamesServiceImpl implements GamesService{
	private GamesDao gamesDao = new GamesDaoImpl();
	/**
	 * 查询上架日期最新的四个游戏
	 */
	@Override
	public List<Games> topFourGames() {
		return gamesDao.topFour();
	}
	/**
	 * 查询好评次数最多的前六个游戏
	 */
	@Override
	public List<Games> topSixGames() {
		return gamesDao.topSix();
	}
	/**
	 * 通过游戏编号查询
	 */
	@Override
	public Games findGamesByGamesId(Integer gamesId) {
		return gamesDao.findByGamesId(gamesId);
	}
	/**
	 * 查询所有游戏
	 */
	@Override
	public List<Games> findAllGames() {
		return gamesDao.findAll();
	}
	
	/**
	 * 根据类型，价格，名称实现组合查询
	 */
	@Override
	public List<Games> findAllGamesByCondition(Integer typeId, BigDecimal minPrice, BigDecimal maxPrice, String gamesName) {
		StringBuilder gn = new StringBuilder();
		String g = null;
		if(gamesName!=null&&!"".equals(gamesName)) {
			g = gn.append("%").append(gamesName).append("%").toString();
		}
		return gamesDao.findAllByCondition(typeId, minPrice, maxPrice, g);
	}
	
	/**
	 * 
	 */
	@Override
	public PageInfo<Games> getGoodsListByPage(Integer typeId, BigDecimal minPrice, BigDecimal maxPrice,
			String gamesName, int pageNum, int pageSize) {
		StringBuilder gn = new StringBuilder();
		String g = null;
		if(gamesName!=null&&!"".equals(gamesName)) {
			g = gn.append("%").append(gamesName).append("%").toString();
		}
		
		List<Games> data = gamesDao.findPageByCondition(typeId, minPrice, maxPrice, g, pageNum, pageSize);
		int total = gamesDao.countByCondition(typeId, minPrice, maxPrice, g);
		PageInfo<Games> pageInfo = new PageInfo<Games>(data, pageNum, pageSize, total);
		return pageInfo;
	}
	/**
	 * 查询下单量最多的前五个游戏
	 */
	@Override
	public List<Games> topFiveGames() {
		return gamesDao.topFive();
	}
	
	

}
